﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections.Generic;
using SharePoint.Silverlight.Clock.ControlTemplates.SharePoint.Silverlight.Clock;
using SharePoint.Silverlight.Clock.EditorParts;


namespace SharePoint.Silverlight.Clock
{
    [ToolboxItemAttribute(false)]
    public class ClockWebPart : WebPart
    {
        #region Properties

        private string _clockTitle = "Clock Title";
        [Personalizable(PersonalizationScope.Shared),
            WebBrowsable(false)]
        public string ClockTitle { get { return _clockTitle; } set { _clockTitle = value; } }

        private bool _showDigitalClock = true;
        [Personalizable(PersonalizationScope.Shared),
            WebBrowsable(false)]
        public bool ShowDigitalClock { get { return _showDigitalClock; } set { _showDigitalClock = value; } }

        private bool _showSecondHand = true;
        [Personalizable(PersonalizationScope.Shared),
            WebBrowsable(false)]
        public bool ShowSecondHand { get { return _showSecondHand; } set { _showSecondHand = value; } }

        private bool _showMilliHand = true;
        [Personalizable(PersonalizationScope.Shared),
            WebBrowsable(false)]
        public bool ShowMilliHand { get { return _showMilliHand; } set { _showMilliHand = value; } }

        private bool _showTenthsHand = true;
        [Personalizable(PersonalizationScope.Shared),
            WebBrowsable(false)]
        public bool ShowTenthsHand { get { return _showTenthsHand; } set { _showTenthsHand = value; } }

        //0 - Client time zone
        private string _timeZoneId = "0";
        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(false)]
        public string ClockTimeZoneId { get { return _timeZoneId; } set { _timeZoneId = value; } }
        
        #endregion

        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/SharePoint.Silverlight.Clock/ClockWebPart/ClockWebPartUserControl.ascx";

        protected override void CreateChildControls()
        {
            Control control = Page.LoadControl(_ascxPath);
            Controls.Add(control);
        }

        public override EditorPartCollection CreateEditorParts()
        {
            List<EditorPart> editors = new List<EditorPart>();
            editors.Add(
               new EditorBase { ID = "EditorBase", Title = "Clock settings" });


            return new EditorPartCollection(editors);
            //return base.CreateEditorParts();
        }
    }
}
